<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/8/20
 * Time: 14:35
 */

namespace App\Http\Controllers\Api\Passenger;


use App\Http\Controllers\Controller;
use App\Services\RechargeService;
use Illuminate\Http\Request;

class RechargeController extends Controller
{
    /**
     * 充值记录列表
     */
    public function lists(Request $request, RechargeService $service)
    {
        $data = $request->post();
        $companyId = (int)$request->post('company_id', '');   //公司
        $pageSize = (int)$request->post('page_size', 10);
        $list = $service->getList($companyId, $data, $pageSize);
        return $this->sendJson($list);
    }

    /**
     * 平台充值
     */
    public function invest(Request $request, RechargeService $service)
    {
        $user_id = (int)$request->post('user_id', '');   //用户ID
        $price = (double)$request->post('price', 0);   //充值金额
        if(empty($user_id) && empty($price))
            return $this->sendError('用户Id和充值金额必须');
        if ($service->invest($user_id, $price)) {
            return $this->sendSuccess('充值成功');
        }
        return $this->sendError('充值失败');
    }
}